package com.lagou.edu.controller;

import com.lagou.edu.pojo.Resume;
import com.lagou.edu.service.ResumeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * @author 黄子濠
 * @date 2020/7/12 20:23
 */
@Controller
@RequestMapping("/resume")
public class ResumeController {
    @Autowired
    private ResumeService resumeService;

    @RequestMapping("/list")
    public ModelAndView list(Resume resume) throws Exception {
        ModelAndView mv = new ModelAndView();
        List<Resume> resumes = resumeService.queryResumeList();
        mv.addObject("list",resumes);
        mv.setViewName("resumeList");
        return mv;
    }

    @RequestMapping("/one")
    public ModelAndView one(Long id) throws Exception {
        ModelAndView mv = new ModelAndView();
        Resume resume = resumeService.one(id);
        mv.addObject("resume",resume);
        mv.setViewName("resume");
        return mv;
    }

    @PostMapping("/add")
    public String add(Resume resume){
        resumeService.add(resume);
        return "redirect:/resume/list";
    }

    @PostMapping("/edit")
    public String edit(Resume resume) {
        resumeService.edit(resume);
        return "redirect:/resume/list";
    }

    @RequestMapping("/delete")
    public String delete(Long id){
        resumeService.delete(id);
        return "redirect:/resume/list";
    }
}
